﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DoodJetView.VuesPartielles;
using DoodJetView.VuesPartielles.Reservation;
using DoodJetView.Core;
using Doo_JetDAL;
using DoodJetView.Core.Client;
using System.Drawing.Printing;
using DoodJetView.VuesPartielles.Employes;

namespace DoodJetView
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        
        
        private Run run;

        public MainWindow(Run run)
        {
            InitializeComponent();
            GestionMarketing();
            this.run = run;
            this.ContentGrid.Children.Add(new DashBoard());
        }

        private void GestionMarketing()
        {
            //Chargement des Activités 
            using (DataEntities db = new DataEntities())
            {
                List<client> clients = db.client.ToList();
                foreach (client c in clients)
                {
                    if (DateTimeUnixTools.ConvertFromUnixTimestamp( c.dateNaissance) == DateTime.Now.AddDays(-15))
                    {
                        if (MessageBox.Show("C'est bientôt l'anniversaire du client " + c.nomClient + "faites lui bénéficier d'une remise de 15%.", "ToDO", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        {
                            PrintDialog printDlg = new PrintDialog();
                            FlowDocument doc = CreateFlowDocument();
                            doc.Name = "FlowDoc";
                            IDocumentPaginatorSource idpSource = doc;
                            printDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing."); 
                        }
                    }
                }

            }
        }
        private FlowDocument CreateFlowDocument()
        {
            FlowDocument doc = new FlowDocument();
            Section sec = new Section();
            Paragraph p1 = new Paragraph();
            Bold bld = new Bold();
            bld.Inlines.Add(new Run("First Paragraph"));
            Italic italicBld = new Italic();
            italicBld.Inlines.Add(bld);
            Underline underlineItalicBld = new Underline();
            underlineItalicBld.Inlines.Add(italicBld);
            p1.Inlines.Add(underlineItalicBld);
            sec.Blocks.Add(p1);
            doc.Blocks.Add(sec);
            return doc;

        }
        private void button3_Click(object sender, RoutedEventArgs e)
        {
          
        }

        private void CreateEmployer(object sender, MouseButtonEventArgs e)
        {
            var FormEmployer = new EtapesEmployes(this);
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(FormEmployer);
        }
        private void CreateClient(object sender, MouseButtonEventArgs e)
        {
            var FormClient = new ClientForm();
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(FormClient);
        }
        private void PageClient(object sender, MouseButtonEventArgs e)
        {
            var PageClient = new ClientWindow();
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(PageClient);
        }
        private void CreateEquipement(object sender, MouseButtonEventArgs e)
        {
            var FormEquipement = new EquipementForm(this);
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(FormEquipement);
        }
        private void Window_Closed(object sender, EventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {

        }

        private void CreerReservation(object sender, MouseButtonEventArgs e)
        {
            var user = new ReservationCreation(this);
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(user);
        }
        private void ListReservation(object sender, MouseButtonEventArgs e)
        {
            reservation r = new reservation();
            var user = new ReservationCreation(this);
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(user);
        }

        private void CreerReservaton(object sender, MouseButtonEventArgs e)
        {
            var user = new ReservationCreation(this);
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(user);
        }
        private void AnnulerReservaton(object sender, MouseButtonEventArgs e)
        {

            var user = new ListReservation(this);
            ContentGrid.Children.Clear();
            ContentGrid.Children.Add(user);
        }

        private void ItemsControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}
